package com.daiqiu.manager.controller;

import com.alibaba.druid.pool.DruidPooledConnection;
import com.daiqiu.manager.util.GetSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

@Controller
public class LoginController {

    DruidPooledConnection con = new GetSource().getConnection();

    @RequestMapping(value = "login")
    @ResponseBody
    public boolean login(String id,String passwd) throws SQLException {
        /*
        -------------------------------------------------------------------------------------------------------------------------------
            业务逻辑
        -------------------------------------------------------------------------------------------------------------------------------
         */
        PreparedStatement preparedStatement=con.prepareStatement("SELECT * FROM t_admin WHERE admin_id=? ");
        preparedStatement.setString(1,id);
        System.out.println(id);
        ResultSet resultSet=preparedStatement.executeQuery();
        if(!resultSet.isBeforeFirst()) return false;
        resultSet.next();
        if(!passwd.equals(resultSet.getString(2))){
            return false;
        }
        return true;
    }


    @RequestMapping("getManager")
    public String getManager() {
        return "manager";
    }
}
